﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DAL;
using Model;

namespace StudentManagerPro.Score
{
    public partial class ScoreManage : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            //this.Query.queryEvent += Query1;

            //this.Query.queryEvent1 += Query2;
            if (!IsPostBack)
            {
                //首次加载：初始化班级下拉框
                this.ddlClass.DataSource = new StudentClassService().GetStudentClass();//设置数据源
                this.ddlClass.DataTextField = "ClassName";//设置下拉框显示文本
                this.ddlClass.DataValueField = "ClassId";//设置显示文本对应的值（该值是隐藏的）
                this.ddlClass.DataBind();//调用数据绑定方法
            }
            this.ltaMsg.Text = "";
        }

        //protected void Query1()
        //{
        //    this.gvScoreList.DataSource = new ScoreService().GetScoreList(this.Query.ClassName);
        //    this.gvScoreList.DataBind();
        //}

        //protected void Query2(string className)
        //{
        //    this.gvScoreList.DataSource = new ScoreService().GetScoreList(className);
        //    this.gvScoreList.DataBind();
        //}

        /// <summary>
        /// 提交查询
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnQuery_Click(object sender, EventArgs e)
        {
            this.gvScoreList.DataSource = new ScoreService().GetScoreList(this.ddlClass.SelectedItem.Text);
            this.gvScoreList.DataBind();
        }

        /// <summary>
        /// 动态添加效果：鼠标进入与移除事件效果
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void gvScoreList_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                e.Row.Attributes.Add("onmouseover", "currentcolor=this.style.backgroundColor;this.style.backgroundColor='#6699ff'");
                e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=currentcolor");
            }
        }

        /// <summary>
        /// 数据导出
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void Button1_Click(object sender, EventArgs e)
        {
            string className = this.ddlClass.SelectedItem.Text;
            Response.Redirect("~/Handlers/ExportExcel.ashx?className="+className);
            //Response.Redirect("~/Handlers/Test.ashx");
        }

        /// <summary>
        /// 下载文件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void Button2_Click(object sender, EventArgs e)
        {
            string className = this.ddlClass.SelectedItem.Text;
            Response.Redirect("~/Handlers/DownLoadFile.ashx?filaName=" + "100000");
        }
    }
}